<template>
  <div class="virtual-currency-rank">
    <div class="list"
         v-if="list && list.length>0">
      <div class="list-title">
        <span>排名</span>
        <span>{{identity}}</span>
        <span>{{rank_type}}</span>
      </div>
      <div class="list-item self">
        <span>
          <i :class="getCls(sort)">{{sort}}</i>
        </span>
        <span>{{nickname}}</span>
        <span class="fontGilroy">{{virtualCurrency}}</span>
      </div>
      <van-list v-model="loading"
                :finished="finished"
                :error.sync="error"
                error-text="请求失败，点击重新加载"
                finished-text=""
                @load="onLoad">
        <div class="list-item"
             v-for="(item, index) in list"
             :key="index">
          <span>
            <i :class="getCls(item.no)">{{getText(item.no)}}</i>
          </span>
          <span>{{item.nickname}}</span>
          <span class="fontGilroy">{{item.virtual_currency}}</span>
        </div>
      </van-list>
    </div>
    <div v-else>
      <no-data :noData="noData"></no-data>
    </div>
  </div>
</template>

<script>
import { getVirtualCurrencyRank } from '@/api/user/member/memberApi'
import noData from '@/components/noData'
// import noRankImg from '@img/user/no-order-rank.png'
import Vue from 'vue'
export default Vue.extend({
  name: 'index',
  components: {
    noData
  },
  props: {
    virtualCurrency: {
      type: String
    }
  },
  data() {
    return {
      noData: {
        width: '214px',
        img: 'https://img.wifenxiao.com/h5-wfx/images/user/no-order-rank.png',
        text: '暂无排名',
        txtMarginTop: '-30px'
      },
      title: '我的排名',
      sort: '',
      nickname: '',
      identity: '用户',
      rank_type: '虚拟币',
      list: [],
      loading: false,
      finished: false,
      error: false,
      p: 2
    }
  },
  methods: {
    getCls(sort) {
      if (sort <= 3) {
        return `icon icon${sort}`
      } else {
        return 'text'
      }
    },
    getText(sort) {
      if (sort > 3) {
        return sort
      }
    },
    getLists() {
      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 10000)

      getVirtualCurrencyRank().then(res => {
        this.$loadingWrap.close()
        if (res.status == 1) {
          const resData = res.data
          this.sort = resData.my_no
          this.nickname = resData.nickname
          this.rank_type = resData.virtual_name
          this.list = resData.virtual_rank
        } else {
          this.$Error(res.msg)
        }
      })
    },
    onLoad() {
      this.loading = true
      const data = {
        p: this.p
      }
      getVirtualCurrencyRank(data)
        .then(res => {
          this.loading = false
          if (res.data.virtual_rank && res.data.virtual_rank.length) {
            this.list.push(...res.data.virtual_rank)
            this.p++
          } else {
            this.finished = true
          }
        })
        .catch(() => {
          this.error = true
        })
    }
  },
  created() {
    this.getLists()
  },
  // mounted() {
  //   // 小程序触底加载更多
  //   window.addEventListener('reachbottom', () => {
  //     // console.log('rank_reachbottom')
  //     this.onLoad()
  //   })
  // }
})
</script>

<style lang="scss">
@import "src/styles/variables";
@import "src/styles/mixin";
.virtual-currency-rank{
  .charges-top {
    height: 360px;
    // line-height: 80px;
    text-align: center;
    background-color: #f0f0f0;
    background: url("https://img.wifenxiao.com/h5-wfx/images/user/point_bg_rank.png") no-repeat;
    background-size: 100% 100%;
    padding: 76px 0 0;
    color: #fff;
    p:first-child {
      font-size: 72px;
    }
    p:last-child {
      font-size: 28px;
      margin-top: 16px;
      // font-weight: bold;
      letter-spacing: 2px;
      color: #f4f4f4;
    }
  }
  .list {
    margin: 20px 30px 0;
    overflow: hidden;
    &-title {
      display: flex;
      align-items: center;
      height: 90px;
      color: #999999;
      font-size: 26px;
      span {
        font-size: 28px;
        color: #8e8179;
        &:nth-child(1) {
          width: 20%;
          margin-right: 8%;
          text-align: center;
        }
        &:nth-child(2) {
          width: 40%;
          margin-right: 2%;
        }
        &:nth-child(3) {
          width: 30%;
          text-align: right;
          padding-right: 43px;
          box-sizing: border-box;
        }
      }
    }
    &-item {
      height: 110px;
      display: flex;
      align-items: center;
      border-bottom: 1px solid #ededed;
      &.self {
        border: 0;
        line-height: 120px;
        background: rgba(255, 204, 212, 1);
        box-shadow: 0px 8px 10px 0px rgba(252, 151, 157, 0.25);
        border-radius: 10px;
      }
      span {
        font-size: 28px;
        &:nth-child(1) {
          width: 20%;
          margin-right: 8%;
        }
        &:nth-child(2) {
          width: 40%;
          margin-right: 2%;
          @include showEllipsis;
        }
        &:nth-child(3) {
          width: 30%;
          font-size: 32px;
          font-weight: bold;
          color: #fd2049;
          text-align: right;
          padding-right: 35px;
          box-sizing: border-box;
        }
        .icon,
        .text {
          display: block;
          width: 80px;
          height: 40px;
          margin: 0 auto;
          line-height: 40px;
          font-weight: bold;
          text-align: center;
          // float: left;
          background-size: auto 100%;
          background-position: center;
          background-repeat: no-repeat;
          &.icon1 {
            background-image: url("https://img.wifenxiao.com/h5-wfx/images/user/No1.png");
          }
          &.icon2 {
            background-image: url("https://img.wifenxiao.com/h5-wfx/images/user/No2.png");
          }
          &.icon3 {
            background-image: url("https://img.wifenxiao.com/h5-wfx/images/user/No3.png");
          }
        }
      }
    }
  }
}
</style>